/**
 * Copyright (C), 2015-2018, XXX有限公司
 * FileName: SendSmsController
 * Author:   sjkyll
 * Date:     2018-07-26 11:34
 * Description: 接收短信接口，调用后台程序进行发送
 * <author>          <time>          <version>          <desc>
 * 作者姓名         修改时间           版本号            描述
 */
package com.cdqidi.smsservice.controller.api;

import com.cdqidi.smsservice.dto.SmsMessage;
import com.cdqidi.smsservice.exception.ApiException;
import com.cdqidi.smsservice.service.SendSmsService;
import com.cdqidi.smsservice.util.ApiLoginUtil;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.ArrayList;
import java.util.List;

/**
 * 〈一句话功能简述〉<br>
 *
 * @author sjkyll
 * @create 2018-07-26 11:34
 * @since 1.0.0
 */
@RestController
@RequestMapping("/api/")
@Slf4j
public class SendSmsController {
    private final SendSmsService sndSmsService;

    @Autowired
    public SendSmsController(SendSmsService sndSmsService) {
        this.sndSmsService = sndSmsService;
    }

    @RequestMapping(value = "/sms")
    public List<String> sendSms(@Validated @RequestBody SmsMessage msg) throws ApiException {
        log.debug("接收到的参数,appId: " + ApiLoginUtil.getApiLogin().getAppId() + ",ip: " + ApiLoginUtil.getApiLogin().getIp() + ",手机号: " + msg.getMobile());
        List<String> list = new ArrayList<>(1);
        Integer size = sndSmsService.sendAp(msg);
        list.add("短信成功提交数量： " + size + "条");
        return list;
    }
}